const {getWeatherData} = require('../../../api/home')

Page({
  data: {
    height:'',
    region:['四川省', '成都市', '武侯区'],
    weather:'',
    page:'1'

  },
  //地点选择器
  async bindRegionChange (e) {
    const [province,city,county]  = e.detail.value
    const res = await getWeatherData({province,city,county})
    this.data.weather = res.data.data.forecast_24h
    this.setData({
      weather:that.data.weather,
      region: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
     let province = this.data.region[0]
    let city = this.data.region[1]
    let county = this.data.region[2]
    let that = this
     // 监听窗口高度
     wx.getSystemInfo({
      success: (res) => {
        this.setData({
          height: res.windowHeight-40
        })
      },
    })
// 请求默认地址的天气
    wx.request({
      url: 'https://wis.qq.com/weather/common?source=xw&weather_type=forecast_1h|forecast_24h|index|alarm|limit|tips&province='+province+'&city='+city+'&county='+county,
      method:'GET',
      success (res) {
        that.data.weather = res.data.data.forecast_24h
        that.setData({
          weather:that.data.weather
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage () {

  }
})